package com.kinyx.framework.constraints;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;

import com.kinyx.framework.constraints.Text.Validator;
import com.kinyx.framework.file.KPropertiesReader;

/**
 * 文本验证注解
 */
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = Validator.class)
public @interface Text {

	public static final String REGEX = KPropertiesReader.getStringValue(Configs.PROPERTIES, Text.class.getSimpleName(), "["

			// 字母
			+ "a-zA-Z"
			// 空格
			+ "\\s"
			// 中文
			+ "\u4e00-\u9fa5"
			// 符号（通用）
			+ "\\~" + "\\`" + "\\!" + "\\@" + "\\#" + "\\$" + "\\%" + "\\^" + "\\&" + "\\*" + "\\(" + "\\)" + "\\-" + "\\_" + "\\+" + "\\=" + "\\{" + "\\}" + "\\|" + "\\[" + "\\]" + "\\\\" + "\\:" + "\\;" + "\\\"" + "\\'" + "\\<" + "\\>" + "\\?" + "\\," + "\\." + "\\/"
			// 符号（中文）
			+ "·" + "！" + "￥" + "……" + "（" + "）" + "——" + "【" + "】" + "、" + "：" + "；" + "“" + "”" + "‘" + "’" + "《" + "》" + "，" + "。" + "？"

			+ "]+");

	String message() default "";

	Class<?>[] groups() default {};

	Class<? extends Payload>[] payload() default {};

	class Validator extends RegexMatchValidator<Text> {

		@Override
		protected String getRegex() { return REGEX; }

	}

}
